<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 16] MessageFormat</TITLE>
<META NAME="author" CONTENT="Mark Grand and Jonathan Knudsen">
<META NAME="date" CONTENT="Fri Aug  8 17:31:14 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java">
<META NAME="title" CONTENT="Java Fundamental Classes Reference">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java Fundamental Classes Reference" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch16_12.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 16<br>The java.text Package</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch16_14.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=refnamediv>
<H1>MessageFormat</H1>

<H2>Name</H2>

MessageFormat

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch16-REFSECT1-AUTOID.91">Synopsis</A></h2>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Class Name:<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>java.text.MessageFormat</tt>

<p>
<DT CLASS=varlistentry>Superclass:<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>java.text.Format</tt>

<p>
<DT CLASS=varlistentry>Immediate Subclasses:<br>
<DD>

<P CLASS=para>
None

<p>
<DT CLASS=varlistentry>Interfaces Implemented:<br>
<DD>

<P CLASS=para>
None

<p>
<DT CLASS=varlistentry>Availability:<br>
<DD>

<P CLASS=para>
New as of JDK 1.1 </DL>
</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch16-REFSECT1-AUTOID.92">Description</A></h2>

<P CLASS=para>
The <tt CLASS=literal>MessageFormat</tt> class constructs textual messages using a formatting pattern string. Conceptually, 
the class functions much like <tt CLASS=literal>printf()</tt> 
in C. Syntactically, however, it is quite different. A <tt CLASS=literal>MessageFormat</tt> 
object uses a pattern string; formatted arguments are placed into the pattern 
string to produce a resulting string. Arguments are delimited by matching 
sets of curly braces and may include additional information about how that 
data should be formatted. For example, consider the following code: 

<DIV CLASS=screen>
<P>
<PRE>
String message = 
  "Boot of server {0}began at {1, time}on {1, date, full}.";
MessageFormat boot = new MessageFormat(message);
Date now = new Date();
Object[] arguments = {"luna3", now};
System.out.println(boot.format(arguments));
</PRE>
</DIV>

<P CLASS=para>
This code produces the following output: 

<DIV CLASS=screen>
<P>
<PRE>
Boot of server luna3 began at 11:13:22 AM on Monday, March 03, 1997.
</PRE>
</DIV>

<P CLASS=para>
Each of the arguments is numbered and includes an optional type and an 
optional style. In the example above, <tt CLASS=literal>{1,</tt> 
<tt CLASS=literal>date,</tt> <tt CLASS=literal>full}</tt> 
indicates that the argument at index <tt CLASS=literal>1</tt> in the argument array should be 
formatted using a <tt CLASS=literal>DateFormat</tt> 
object with the <tt CLASS=literal>FULL</tt> style. 
The allowed types and styles are: 

<DIV CLASS=informaltable>
<P>
<TABLE CLASS=INFORMALTABLE>
<TR CLASS=row>
<TH ALIGN="LEFT">Type</TH>
<TH ALIGN="LEFT">Object</TH>
<TH ALIGN="LEFT">Styles</TH>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>choice</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>ChoiceFormat</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<I CLASS=emphasis>pattern</I></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>date</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>DateFormat</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>short</tt>, <tt CLASS=literal>medium</tt>, 
<tt CLASS=literal>long</tt>, <tt CLASS=literal>full</tt>, 
<I CLASS=emphasis>pattern</I></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>number</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>NumberFormat</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>integer</tt>, <tt CLASS=literal>percent</tt>, 
<tt CLASS=literal>currency</tt>, <I CLASS=emphasis>pattern</I></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>time</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>DateFormat</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>short</tt>, <tt CLASS=literal>medium</tt>, 
<tt CLASS=literal>long</tt>, <tt CLASS=literal>full</tt>, 
<I CLASS=emphasis>pattern</I></TD>
</TR>
</TABLE>
<P>
</DIV>

<P CLASS=para>
For the <tt CLASS=literal>date</tt> and <tt CLASS=literal>time</tt> 
types, the styles correspond to the styles, or lengths, of the resulting 
date and time strings. You can also specify a date or time pattern string 
as you would for creating a <tt CLASS=literal>SimpleDateFormat</tt> 
object. For the <tt CLASS=literal>number</tt> type, 
the styles correspond to formatting normal numbers, percentage values, 
and currency values. You can also specify a number pattern string as you 
would for creating a <tt CLASS=literal>DecimalFormat</tt> 
object. For the <tt CLASS=literal>choice</tt> type, 
you can specify a choice pattern as you would for creating a <tt CLASS=literal>ChoiceFormat</tt> 
object. If no type is specified, the argument should be a string. 

<P CLASS=para>
The following example shows how to use a <tt CLASS=literal>choice</tt> 
format pattern with a <tt CLASS=literal>MessageFormat</tt>: 

<DIV CLASS=screen>
<P>
<PRE>
Object[] arguments = {new Integer(1)};
String grammar = "At last count, {0}server{0, choice, 0#s|1#|1&lt;s}
 {0, choice, 0#were|1#was|1&lt;were}booted.";
MessageFormat booted = new MessageFormat(grammar);
System.out.println(booted.format(arguments));
arguments[0] = new Integer(2);
System.out.println(booted.format(arguments));
</PRE>
</DIV>

<P CLASS=para>
This example produces the following output: 

<DIV CLASS=screen>
<P>
<PRE>
At last count, 1 server was booted.
At last count, 2 servers were booted.
</PRE>
</DIV>

<P CLASS=para>
As an alternative to specifying all of the formatting in the pattern string, 
you can use an array of <tt CLASS=literal>Format</tt> 
objects to format the arguments. You can specify this array using <tt CLASS=literal>setFormats()</tt>. 

<P CLASS=para>
Note that you create <tt CLASS=literal>MessageFormat</tt> 
objects directly, rather than through factory methods. This is because 
<tt CLASS=literal>MessageFormat</tt> does not implement 
any locale-specific behavior. To produce properly internationalized output, 
the pattern string that is used to construct a <tt CLASS=literal>MessageFormat</tt> 
should come from a <tt CLASS=literal>ResourceBundle</tt> 
instead of being embedded in the code. 

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch16-REFSECT1-AUTOID.93">Class Summary</A></h2>

<DIV CLASS=screen>
<P>
<PRE>
public class java.text.MessageFormat extends java.text.Format {
  // Constructors
  public MessageFormat(String pattern);
  // Class Methods
  public static String format(String pattern, Object[] arguments);
  // Instance Methods
  public void applyPattern(String newPattern);
  public Object clone();
  public boolean equals(Object obj); 
  public final StringBuffer format(Object source, StringBuffer result, 
                            FieldPosition ignore);
  public final StringBuffer format(Object[] source, StringBuffer result, 
                            FieldPosition ignore);
  public Format[] getFormats();
  public Locale getLocale();
  public int hashCode();
  public Object[] parse(String source);
  public Object[] parse(String source, ParsePosition status);
  public Object parseObject(String text, ParsePosition status);
  public void setFormat(int variable, Format newFormat);
  public void setFormats(Format[] newFormats);
  public void setLocale(Locale theLocale);
  public String toPattern();
}
</PRE>
</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch16-REFSECT1-AUTOID.94">Constructors</A></h2>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.193">MessageFormat</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.220">public MessageFormat(String pattern)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>pattern</tt><br>
<DD>

<P CLASS=para>
The pattern string. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This constructor creates a <tt CLASS=literal>MessageFormat</tt> 
with the given formatting pattern string. </DL>
</DIV>

</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch16-REFSECT1-AUTOID.95">Class Methods</A></h2>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.194">format</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.221">public static String format(String pattern, Object[] arguments)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>pattern</tt><br>
<DD>

<P CLASS=para>
The pattern string.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>arguments</tt><br>
<DD>

<P CLASS=para>
An array of arguments. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Calling this <tt CLASS=literal>static</tt> method 
is equivalent to constructing a <tt CLASS=literal>MessageFormat</tt> 
using the given formatting pattern string and asking it to format the given 
arguments with the <tt CLASS=literal>format()</tt> 
method. </DL>
</DIV>

</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch16-REFSECT1-AUTOID.96">Instance Methods</A></h2>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.195">applyPattern</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.222">public void applyPattern(String pattern)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>pattern</tt><br>
<DD>

<P CLASS=para>
The pattern string. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method tells this <tt CLASS=literal>MessageFormat</tt> 
to use the given formatting pattern to format and parse arguments. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.196">clone</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.223">public Object clone()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
A copy of this <tt CLASS=literal>MessageFormat</tt>. 

<p>
<DT CLASS=varlistentry>Overrides<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>Format.clone()</tt> 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method creates a copy of this <tt CLASS=literal>MessageFormat</tt> 
and then returns it. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.197">equals</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.224">public boolean equals(Object obj)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>obj</tt><br>
<DD>

<P CLASS=para>
The object to be compared 
with this object. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>true</tt> if the objects are equal; 
<tt CLASS=literal>false</tt> if they are not. 

<p>
<DT CLASS=varlistentry>Overrides<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>Format.equals()</tt> 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method returns <tt CLASS=literal>true</tt> if 
<tt CLASS=literal>obj</tt> is an instance of <tt CLASS=literal>MessageFormat</tt> 
and is equivalent to this <tt CLASS=literal>MessageFormat</tt>. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.198">format</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.225"><DIV CLASS=screen> <P> <PRE> public StringBuffer format(Object source, StringBuffer result, FieldPosition ignore) </PRE> </DIV></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>source</tt><br>
<DD>

<P CLASS=para>
The object to be formatted.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>result</tt><br>
<DD>

<P CLASS=para>
A <tt CLASS=literal>StringBuffer</tt> 
on which to append the formatted information.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>ignore</tt><br>
<DD>

<P CLASS=para>
Ignored. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The given buffer <tt CLASS=literal>result</tt> with 
the formatted representation of the object appended to it. 

<p>
<DT CLASS=varlistentry>Overrides<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>Format.format(Object, 
StringBuffer, FieldPosition)</tt> 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method formats the given object and appends the result to the given 
<tt CLASS=literal>StringBuffer</tt>. The method assumes 
that the given object is an array of arguments. </DL>
</DIV>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.226"><DIV CLASS=screen> <P> <PRE> public StringBuffer format(Object[] source, StringBuffer result, FieldPosition ignore) </PRE> </DIV></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>source</tt><br>
<DD>

<P CLASS=para>
The object array to be formatted.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>result</tt><br>
<DD>

<P CLASS=para>
A <tt CLASS=literal>StringBuffer</tt> 
on which to append the formatted information.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>ignore</tt><br>
<DD>

<P CLASS=para>
Ignored. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The given buffer <tt CLASS=literal>result</tt> with 
the formatted representation of the object array appended to it. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method formats the given arguments in the object array and appends 
the result to the given <tt CLASS=literal>StringBuffer</tt>. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.199">getFormats</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.227">public Format[] getFormats()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
An array of the formats used by this <tt CLASS=literal>MessageFormat</tt>. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method returns the format objects that this <tt CLASS=literal>MessageFormat</tt> 
uses. Note that formats are numbered according to the order in which they 
appear in the formatting pattern string, not according to their specified 
argument numbers. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.200">getLocale</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.228">public Locale getLocale()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>

<tt CLASS=literal>The Locale</tt> of this
<tt CLASS=literal>MessageFormat</tt>.
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method returns the locate for this <tt CLASS=literal>MessageFormat</tt>. 
This locale is used to get default date, time, and number formatters. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.201">hashCode</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.229">public int hashCode()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
A hashcode for this object. 

<p>
<DT CLASS=varlistentry>Overrides<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>Object.hashCode()</tt> 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method returns a hashcode for this <tt CLASS=literal>MessageFormat</tt>. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.202">parse</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.230">public Object[] parse(String source) throws ParseException</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>source</tt><br>
<DD>

<P CLASS=para>
The string to be parsed. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
An array of objects represented by the given string. 

<p>
<DT CLASS=varlistentry>Throws<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>ParseException</tt><br>
<DD>

<P CLASS=para>
If the text cannot be parsed. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method parses arguments from the given string, which should be in 
the format given by the formatting pattern string of this <tt CLASS=literal>MessageFormat</tt>. 
If the string is not correctly formatted, an exception is thrown. </DL>
</DIV>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.231">public Object[] parse(String source, ParsePosition status)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>source</tt><br>
<DD>

<P CLASS=para>
The string to be parsed.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>status</tt><br>
<DD>

<P CLASS=para>
A <tt CLASS=literal>ParsePosition</tt> 
object that specifies a position in the string. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
An array of objects represented by the test starting at the given position. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method parses arguments from the given string, starting at the specified 
position. The string should be in the format given by the formatting pattern 
string of this <tt CLASS=literal>MessageFormat</tt>. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.203">parseObject</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.232">public Object parseObject(String text, ParsePosition status)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>text</tt><br>
<DD>

<P CLASS=para>
The string to be parsed.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>status</tt><br>
<DD>

<P CLASS=para>
A <tt CLASS=literal>ParsePosition</tt> 
object that specifies a position in the string. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The object represented by the test starting at the given position. 

<p>
<DT CLASS=varlistentry>Overrides<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>Format.parseObject(String, 
ParsePosition)</tt> 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method parses arguments from the given string, starting at the specified 
position. The string should be in the format given by the formatting pattern 
string of this <tt CLASS=literal>MessageFormat</tt>. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.204">setFormat</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.233">public void setFormat(int variable, Format newFormat)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>variable</tt><br>
<DD>

<P CLASS=para>
The index of an argument in the pattern string.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>newFormat</tt><br>
<DD>

<P CLASS=para>
The format object to use. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method sets the <tt CLASS=literal>Format</tt> 
object that is used for the given argument in the formatting pattern string. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.205">setFormats</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.234">public void setFormats(Format[] newFormats)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>newFormats</tt><br>
<DD>

<P CLASS=para>
The format objects to use. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method sets the <tt CLASS=literal>Format</tt> 
objects that format the arguments of this <tt CLASS=literal>MessageFormat</tt>. 
Note that formats are numbered according to the order in which they appear 
in the formatting pattern string, not according to their specified argument 
numbers. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.206">setLocale</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.235">public void setLocale(Locale theLocale)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>theLocale</tt><br>
<DD>

<P CLASS=para>
The new locale. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method sets the <tt CLASS=literal>Locale</tt> 
object that generates the default date, time, and number format 
objects. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch16-REFSECT2-AUTOID.207">toPattern</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch16-REFSECT3-AUTOID.236">public String toPattern()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The pattern string of this <tt CLASS=literal>MessageFormat</tt>. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method returns the pattern string of this <tt CLASS=literal>MessageFormat</tt>. </DL>
</DIV>

</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch16-REFSECT1-AUTOID.97">Inherited Methods</A></h2>

<DIV CLASS=informaltable>
<P>
<TABLE CLASS=INFORMALTABLE>
<TR CLASS=row>
<TH ALIGN="LEFT">Method</TH>
<TH ALIGN="LEFT">Inherited From</TH>
<TH ALIGN="LEFT">Method</TH>
<TH ALIGN="LEFT">Inherited From</TH>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>finalize()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>format(Object)</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Format</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>getClass()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>notify()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>notifyAll()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>parseObject(String)</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Format</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>toString()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>wait()</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
</TR>
<TR CLASS=row>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>wait(long)</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>wait(long, int)</tt></TD>
<TD ALIGN="LEFT">

<P CLASS=para>
<tt CLASS=literal>Object</tt></TD>
</TR>
</TABLE>
<P>
</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch16-REFSECT1-AUTOID.98">See Also</A></h2>

<P CLASS=para>
<tt CLASS=literal>ChoiceFormat</tt>, 
<tt CLASS=literal>DateFormat</tt>, 
<tt CLASS=literal>FieldPosition</tt>, 
<tt CLASS=literal>Format</tt>, 
<tt CLASS=literal>Locale</tt>, 
<tt CLASS=literal>NumberFormat</tt>, 
<tt CLASS=literal>ParseException</tt>, 
<tt CLASS=literal>ParsePosition</tt>, 
<tt CLASS=literal>ResourceBundle</tt>, 
<tt CLASS=literal>String</tt>, 
<tt CLASS=literal>StringBuffer</tt> 
</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch16_12.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch16_14.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>Format</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>NumberFormat</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
